﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KongMing.ORM.FreeSqlDemo.Models;

namespace KongMing.ORM.FreeSqlDemo
{
    internal class BookDemo
    {
        public static void Go()
        {
            using var fsql = FreeSqlHelper.GetFreeSql(FreeSql.DataType.SqlServer, "server=.;Database=KongMing.BookDB;Uid=km;Pwd=666;");
            /*
            using(var uow = fsql.CreateUnitOfWork())
            {

            }
            var bookRepository = fsql.GetRepository<Book>();
            var book = bookRepository.Where(x => x.Title.Contains("三体")).ToOne();
            book.SellPrice = 2000m;
            bookRepository.Update(book);
            var list = bookRepository.Where(x => x.SellPrice > 20).ToList();

            var _bookRepository = new BookRepository(fsql);
            var _list = _bookRepository.Where(x => x.SellPrice > 20).OrderByDescending(x => x.SellPrice).ToList();
            */
            var tab3List = fsql.Select<FreeTable3>().Include(x => x.FreeTable2.FreeTable1).ToList(true);
            var tab3 = fsql.Select<FreeTable3>().Include(x => x.FreeTable2.FreeTable1).First();

            tab3.Name = "dasda";
            fsql.Update<FreeTable3>(tab3).ExecuteAffrows();
            var tab2 = new FreeTable2() { Name = "dasds", Value = "dasa", IdFk = 1 };
            
        }
    }
}
